{extend name="public/layout" /}
{block name="head"}{/block}
{block name="body"}
<?php
$class_template = D('cms.Class')->getTplList('item_list_');
$class_template = array_column($class_template,'name');
$class_template = json_encode($class_template);
$info_template = D('cms.Class')->getTplList('item_info_');
$info_template = array_column($info_template,'name');
$info_template = json_encode($info_template);
?>
<body>
<div class="container-fluid p-t-15">
  <div class="card p-15">
    <div class="p-b-10">
      <a href="javascript:void(0);" onclick="doAction.add()" class="btn btn-primary"><i class="mdi mdi-plus"></i> 添加</a>
      <a href="javascript:void(0);" class="btn btn-default" onclick="doAction.refresh();">
        <i class="mdi mdi-refresh"></i> 刷新
      </a>
    </div>
    <div class="table-responsive">
      <table id="grid" class="table table-bordered">
        <thead>
        <tr>
          <th style="width:60px">ID</th>
          <th>分类名称</th>
          <th style="width:160px">类型</th>
          <th style="width:160px">列表模板</th>
          <th style="width:160px">内容模板</th>
          <th style="width:160px">显示</th>
          <th style="width:160px">排序</th>
          <th style="width:250px">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="tree" id="vo"}
        <tr class="treegrid-{$vo.id} {gt name='$vo.pid' value='0'} treegrid-parent-{$vo.pid}{/gt}">
          <td>{$vo.id}</td>
          <td>
            <a href="javascript:void(0)" class="f-editable"
               data-type="text"
               data-name="name"
               data-pk="{$vo.id}"
               data-url="editable.html?valid=require">{$vo.name}</a>
          </td>
          <td>
            {if $vo.class_type==1}
            <span class="label label-info">单页栏目</span>
            {elseif $vo.class_type==2}
            <span class="label label-warning">外链栏目</span>
            {else}
            <span class="label label-default">普通栏目</span>
            {/if}
          </td>
          <td>
            <a href="javascript:void(0)" class="f-editable"
               data-type="select"
               data-source="{$class_template}"
               data-name="class_tpl"
               data-pk="{$vo.id}"
               data-value="{$vo.class_tpl}"
               data-url="editable.html">{$vo.class_tpl}</a>
          </td>
          <td>
            <a href="javascript:void(0)" class="f-editable"
               data-type="select"
               data-source="{$info_template}"
               data-name="content_tpl"
               data-pk="{$vo.id}"
               data-value="{$vo.content_tpl}"
               data-url="editable.html">{$vo.content_tpl}</a>
          </td>
          <td>
            {:\\helper\\Form::_switch('is_show',$vo.is_show,[
            "data-id"=>$vo['id']
            ])}
          </td>
          <td>
            <a href="javascript:void(0)" class="f-editable"
               data-type="text"
               data-name="show_order"
               data-pk="{$vo.id}"
               data-url="editable.html">{$vo.show_order}</a>
          </td>
          <td>
            <a href="javascript:void(0)" onclick="doAction.add('{$vo.id}')" class="btn-xs btn btn-info">
              <i class="mdi mdi-plus"></i> 添加</a>
            <a href="javascript:void(0)" onclick="doAction.edit('{$vo.id}')" class="btn-xs btn btn-primary">
              <i class="mdi mdi-pencil"></i> 编辑</a>
            <a href="javascript:void(0)" class="btn-xs btn btn-danger" onclick="helper.doConfirm(this,'refresh')"
               data-url="del.html"
               data-params="id={$vo.id}"
               data-msg="确认要删除该栏目分类吗?"><i class="mdi mdi-archive"></i> 删除</a>
          </td>
        </tr>
        {/volist}
        </tbody>
      </table>
    </div>
  </div>
</div>
<script>
  helper.treeTable({treeColumn: 1});
  Do('editable', function () {
    $('.f-editable').editable();
  });
  //分类状态切换
  $("input[name='is_show']").change(function () {
    var that = $(this);
    var id = that.data('id');
    layer.confirm('确认修改状态吗?', {icon: 3},
        function (index) {
          helper.getAjax({
            url: '/system/cms.class/set.html',
            data: {id: id},
            success: function (res) {
              if (res.code == 0) {
                that.prop("checked", !$(that).prop("checked"));
                helper.tips(res.msg);
              }
              layer.close(index);
            }
          })
        },
        function (index) { //取消按钮
          that.prop("checked", !that.prop("checked"));
          layer.close(index);
        }
    )
  });
  var doAction = {
    add: function (id) {
      var url = id ? '/system/cms.class/add.html?pid=' + id : '/system/cms.class/add.html';
      helper.createTab({
        title: '添加栏目分类',
        url: url
      });
    },
    edit: function (id) {
      helper.createTab({
        title: '修改栏目分类',
        url: '/system/cms.class/edit.html?id=' + id
      });
    },
    refresh: function () {
      helper.getAjax({
        url: "refresh.html",
        success: function (res) {
          if (res.code == 1) {
            helper.refresh();
          } else {
            helper.tips(res.msg);
          }
        }
      });
    }
  };
</script>
</body>
{/block}